#!/bin/bash
set -e

CURRENT_DIR=$(pwd)
ANALYSE_DIR="$CURRENT_DIR/analyse-problem"
TEMPLATE_AMD64_DIR="$ANALYSE_DIR/template/amd64"
TEMPLATE_ARM64_DIR="$ANALYSE_DIR/template/arm64"
TEMPLATE_MIPS64_DIR="$ANALYSE_DIR/template/mips64el"
TEMPLATE_LOONGARCH64_DIR="$ANALYSE_DIR/template/loongarch64"

if [ -d "$ANALYSE_DIR" ]; then
    rm -rf "$ANALYSE_DIR"
fi

if [ ! -d "$ANALYSE_DIR" ]; then
    mkdir -p "$ANALYSE_DIR"
fi

mkdir -p "$TEMPLATE_AMD64_DIR"
mkdir -p "$TEMPLATE_ARM64_DIR"
mkdir -p "$TEMPLATE_MIPS64_DIR"
mkdir -p "$TEMPLATE_LOONGARCH64_DIR"

cd "$ANALYSE_DIR"

wget --no-check-certificate -P "$TEMPLATE_AMD64_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/template/amd64/kylin-update-desktop-system.json
wget --no-check-certificate -P "$TEMPLATE_ARM64_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/template/arm64/kylin-update-desktop-system.json
wget --no-check-certificate -P "$TEMPLATE_MIPS64_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/template/mips64el/kylin-update-desktop-system.json
wget --no-check-certificate -P "$TEMPLATE_LOONGARCH64_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/template/loongarch64/kylin-update-desktop-system.json
wget --no-check-certificate -P "$ANALYSE_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/uploadMessage.sh
wget --no-check-certificate -P "$ANALYSE_DIR" https://gitee.com/newwangsong/analyse-update/raw/master/fix-system.sh

if [[ $? != 0 ]];then
	echo "执行失败，请检查您的网络连通性,检查后，可重新执行此脚本"
fi
